﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 03/01/2009
// Time: 10:28
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of Employee.
	/// </summary>
	public class Employee : csharp.common.DefaultClass, csharp.common.IClass
	{		
		public Person person = new Person();
		
		#region private declarations
			private String _assist; //Trabalha no atendimento
		#endregion
		
		#region properties
			public bool assist 
			{
				get { return Convert.ToBoolean(_assist); }
				set { _assist = Convert.ToString(value); }
			}
			
		#endregion
		
		public Employee()
		{
			clear();
			gsql.table= "common.employee";
			_sequence = "common.employee_employee_id_seq";
		}
		
		public void clear()
		{
			_assist = Boolean.FalseString;
			person.clear();
		}
		
		
		public override void get(System.Data.DataRow dr)
		{
			_id 		 = dr["employee_id"].ToString();
			person.id = dr["employee_person_id"].ToString();
			person.get();
			_assist	 = dr["employee_assist"].ToString();
		}
		
		public override void setGsql()
		{
			gsql.setValue(person.id , "employee_person_id");
			gsql.setValue(_assist	, "employee_assist");
		}
	}
	
	public class Employees : csharp.common.DefaultList, csharp.common.IList
	{

		public Employees()
		{
			gsql.table = "common.employee";
		}
		
		/*public List<Employee> items
		{
			get { return items; }
		}*/
		
		
		public Employee get(Int32 index)
		{
			return (Employee)items[index];
		}
		
		public Employee get()
		{
			return (Employee)items[index];
		}		
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.sql = "SELECT employee.* "
						+"FROM common.employee "
						+"JOIN common.person ON employee_person_id = person_id "
						+"WHERE person_company_id = "+Information.companyId;
			
			return mountList();
		}
		
		public bool getAssist()
		{
			gsql.prepare();
			gsql.sql = "SELECT employee.* "
						+"FROM common.employee "
						+"JOIN common.person ON employee_person_id = person_id AND employee_assist "
						+"WHERE person_company_id = "+Information.companyId;
			
			return mountList();	
		}
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.executeSql())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				Employee e = new Employee();
				e.get(gsql.getRow(i));
				items.Add(e);
			}
			return true;
		}
	}

}
